<template>
  <div>
    <router-link
      tag="div"
      to="/"
      class="header-abs"
      v-show="showAbs"
    >
      <div class="iconfont header-back-icon">&#xe63f;</div>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" v-bind:style="opacityStyle">
      <router-link tag="div" to="/">
        <div class="iconfont header-fixed-back">&#xe63f;</div>
      </router-link>
      <div>景点详情</div>
    </div>
  </div>
</template>

<script>
export default{
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 55) {
        let opacityValue = top / 100
        opacityValue = opacityValue >= 1 ? 1 : opacityValue
        this.opacityStyle = {
          opacity: opacityValue
        }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    // 全局事件解绑
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
  .header-abs
    position absolute
    top .12rem
    left .12rem
    width .7rem
    height .7rem
    line-height .7rem
    border-radius .35rem
    background rgba(0,0,0,0.8)
    text-align center
    .header-back-icon
      color #fff
  .header-fixed
    z-index 2
    position fixed
    top 0
    left 0
    right 0
    height $headerHeight
    line-height $headerHeight
    background $bgColor
    text-align center
    color $darkTextColor
    .header-fixed-back
      width .64rem
      position absolute
      top 0
      left 0
      text-align center
      font-size .4rem
      color #fff
  .wrapper
    padding-top .15rem
    padding-left .24rem
    line .64rem
    line-height .64rem
</style>
